/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.modules.drawer.rapid;

import static org.anderground.modules.drawer.rapid.Config.tunnelWidth;

import java.util.List;

import org.anderground.core.graphics.Canvas;
import org.anderground.core.graphics.PointF;

public class SimpleLinkDrawer extends LinkDrawer {

	@Override
	public void draw(Canvas canvas, Link link) {
		draw(canvas, link.evenPointF, link.oddPointF, link.colors);
	}

	public void draw(Canvas canvas, PointF from, PointF to, List<Integer> colors) {
		PointF normal = PointF.difference(from, to);
		normal.rotateCW();
		normal.normalize();
		normal.scale(tunnelWidth);
		if (colors.size() == 1) {
			getTunnelPaint().setColor(colors.get(0));
			canvas.drawLine(from, to, getTunnelPaint());
		} else if (colors.size() == 0) {
			canvas.drawLine(from, to, getTransferPaint());
		} else {
			PointF offset = new PointF(normal);
			offset.scale((float) (1 - colors.size()) / 2);
			for (int color : colors) {
				getTunnelPaint().setColor(color);
				canvas.drawLine(PointF.sum(from, offset), PointF
						.sum(to, offset), getTunnelPaint());
				offset.add(normal);
			}
		}
	}

}
